package com.javafactroy.kunlong.bip.icp.common.utils;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;


@Slf4j
public class IpUtils {
    //static long ipv4=NetUtil.ipv4ToLong(s);
    public static int getMsgId() {
        for (String s : NetUtil.localIpv4s()) {

            if (!s.equals("127.0.0.1")) {
                return (int) (NetUtil.ipv4ToLong(s) & 0xffffffff + System.nanoTime() & 0xffffffff);
            }
        }
        return RandomUtil.randomInt();
    }

    public static String localIp() {
        return NetUtil.getLocalhost().toString().substring(1);
    }

    public static void main(String[] args) {
        log.info("ip = {}", localIp());//.toString().substring(1));
    }


}
